/**
 * @author LKQ
 * @date 2022/2/23 12:49
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int countCharacters(String[] words, String chars) {
        int n = chars.length();
        int[] cnt = new int[26];
        for (char c: chars.toCharArray()) {
            cnt[c - 'a'] ++;
        }
        int ans = 0;
        for (String word: words) {
            int[] copy = new int[26];
            System.arraycopy(cnt, 0, copy, 0, 26);
            boolean can = true;
            for (char c: word.toCharArray()) {
                copy[c -'a']--;
                if (copy[c- 'a'] < 0) {
                    can = false;
                    break;
                }
            }
            if (can) {
                ans += word.length();
            }
        }
        return ans;
    }
}
